package coroutines

import kotlinx.coroutines.*
import kotlin.concurrent.thread

/**
 * 协程创建使用
 */

suspend fun main() {
    println("main start:${getNow()}")
//    GlobalScope.launch {
//        println("GlobalScope.launch 我在协程里:${getNow()},thread:${getThread()}")
//    }

    val result:Deferred<Int> =GlobalScope.async {
        println("GlobalScope.async 我在协程里:${getNow()}，thread:${getThread()}")
        14
    }

   val num = result.await() //会阻塞当前线程，等待结果

    runBlocking {
        println("runBlocking 我在协程里:${getNow()}，thread:${getThread()}")
    }

    println("main end:${getNow()}，num:$num")
}